package site.kitcheng.springboottest.infra.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.apache.ibatis.plugin.Interceptor;
import site.kitcheng.springboottest.infra.config.sql.MyBatisSqlInterceptor;

/**
 * ClassName: MybatisPlusConfig
 * Package: site.kitcheng.springboottest.infra.config
 * Description:
 *
 * @Author jiangCheng
 * @Create 2025/1/22 14:35
 * @Version 1.0
 */
@Configuration
@MapperScan("site.kitcheng.springboottest.infra.mapper")
public class MybatisPlusConfig {

    @Bean
    public Interceptor sqlInterceptor() {
        return new MyBatisSqlInterceptor();
    }
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}